package cn.zhx.xa.system.dao;


import cn.zhx.xa.model.entity.SysUserRole;
import cn.zhx.xa.system.mapper.SysUserRoleMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
public class SysUserRoleDao extends ServiceImpl<SysUserRoleMapper, SysUserRole> {
    public void deleteByUserId(Long userId) {
        LambdaQueryWrapper<SysUserRole> sysUserQueryWrapper = new LambdaQueryWrapper<>();
        sysUserQueryWrapper.eq(SysUserRole::getUserId,userId);
        remove(sysUserQueryWrapper);
    }

    public List<Long> findSysUserRoleByUserId(Long userId) {
        // 查询用户角色
        return lambdaQuery()
                .select(SysUserRole::getRoleId)
                .eq(SysUserRole::getUserId,userId)
                .list()
                .stream()
                .map(SysUserRole::getRoleId)
                .toList();

    }
}
